

inherit "inherit/char";


number save(){


//    super.save();

    //过滤不需要存储的数据
    map saveData = ({});
//    foreach(k in this.attr){
//        //这几个属性都不需要存储
//        if( k!="currEnv" && k!="netChannel" && k!="fileAddr" && k!="enemy" && k!="killers" ){
//            saveData[k] = this.attr[k];
//        }
//    }

    string s = toJsonStr(this.attr);
    string df    = "data/user/"+subcut(id(),0,1)+"/"+id();
    writeFile(df,s);
}

 number heartbeat(){


//    println("user心跳");

   string* combatMessage = query("combatMessage");

   if( sizeof(combatMessage)>0 ){//播放战斗日志

       string msg = arrayShift(combatMessage);
       tellObject(this,msg);
       println(msg);
   }else{
      number rwd = query("combat/reward/pot");
      if( rwd ){
        string msg = fmt("本次战斗获得%s修为。",rwd);
        add("pot",rwd);
        tellObject(this,msg);
        //删除相关的key.
        delete("combat/reward/pot");
      }

        //循环战斗 哦也！
       command(this,"kill liapo");
   }


    attack();
    save();
 }




number create(){
    //标记为玩家
    set("isUser",1);

}

//网络错误或者断开咯
number disNetConn(){

    removeNet();

}

//移除网络连接
number removeNet(){
    set("netAgentId",0);
    set("netChannel",0);
}

number restore(){
    string df    = "data/user/"+subcut(id(),0,1)+"/"+id();
    var data = readFile(df);
    data = jsonStrToMap(data);
    if(!mapp(data)) return 0;


    foreach(k in data){
      if( k!="currEnv" && k!="netChannel" && k!="fileAddr" && k!="enemy" && k!="killers" ){
            set(k,data[k]);
       }

    }

    return 1;


}




